//选择农药产品登记证号
layui.use(['form', 'layer', 'laydate', 'table'], function () {
    let form = layui.form;
    let layer = layui.layer;
    let laydate = layui.laydate;
    let table = layui.table;
    //获取选择登记证号url
    let certificateSelectUrl = apiArr[8].trim();
    //方法级渲染
    table.render({
        elem: '#LAY_table_user',
        //url: 'http://127.0.0.1/yj/certificateMessage',
        url: certificateSelectUrl,
        where: {
            deptId: window.parent.$("#departmentId").val(),
            type: 'invalid'
        },
        cols: [
            [{
                type: 'numbers',
                fixed: true //显示序号
            }, {
                checkbox: true,
                fixed: true,
            }, {
                field: 'certificateCode',
                title: '农药登记证号',
                fixed: true,
            }, {
                field: 'registerName',
                title: '农药产品名称',
                fixed: true,
            }]
        ],
        parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.message, //解析提示文本
                "count": res.records, //解析数据长度
                "data": res.rows //解析数据列表
            };
        },
        request: {
            pageName: 'page', //页码的参数名称，默认：page
            limitName: 'rows' //每页数据量的参数名，默认：limit
        },
        id: 'testReload',
        skin: 'line',
        even: true,
        page: true,
        height: 'full-120',
        limit: 20,
        limits: [10, 20, 30, 50]

    });
    let $ = layui.$,
        active = {
            reload: function () {
                var q = formSearchCollection();

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        queryJson: json2Str({
                            groupOp: 'AND',
                            rules: q
                        })
                    },
                    height: 'full-120',
                });
            }
        };
    $('.demoTable .layui-btn').on('click', function () {
        let type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    $("#selectBtn").on("click", function () {
        var checkStatus = table.checkStatus('testReload'); //idTest 即为基础参数 id 对应的值
        if (checkStatus.data.length != 1) {
            layer.msg('请选择一行数据');
            return;
        }
        //console.log(checkStatus.data) //获取选中行的数据
        //console.log(checkStatus.isAll) //表格是否全选
        parent.$('#certificateCode').val(checkStatus.data[0].certificateCode);
        parent.$('#cpmc').val(checkStatus.data[0].registerName);
        closeSubIframe();
    })
    $('.demoTable .layui-btn.layui-btn-primary').on('click', function () {
        $("#form1")[0].reset();
        $('#form1 input[type="hidden"]').val('');
    });

    //选择农药产品登记证号
    $(".layui-icon-search").on("click", function () {
        parent.layer.open({
            title: '选择农药类别',
            type: 2,
            area: ['1200px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            //closeBtn: 1, //1 不显示关闭按钮  
            content: "../../certicateselect/catelogselect/html/index.html"
        });
    });

    $("#cancelBtn").on("click", function () {
        closeSubIframe();
    })

});
/**
 * 关闭子iframe
 */
function closeSubIframe() {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}